Skip to content

feat: Add tools for interacting with the GitHub API - #109

Merged
gadenbuie merged 19 commits into
mainfrom
feat/tools-gh
Oct 21, 2025
Merged

gadenbuie merged 19 commits into
mainfrom
feat/tools-gh

Conversation

@gadenbuie

Copy link
Copy Markdown
Collaborator

Closes #108

This PR adds a new btw_tool_github() tool to the btw collection.

I initially implemented this as several tools, but decided to go in a new direction.

Instead, I settled on a single tool that wraps gh::gh() and lets the LLM just write code to interact with the GitHub API. We do not let the model just "write code", instead, it's allowed to write calls to gh() and gh_whoami(). There are a very limited number of functions available to the LLM for use, where basically almost anything other than a bare call to gh() will fail.

Additionally, there's an endpoint filtering mechanism in place that includes a large built-in allow and block lists to limit the LLM to using specific endpoints. There's also an options mechanism where users can add additional allow and block rules, either via R options or in the btw.md YAML file.

This commit introduces 8 new GitHub tools that leverage the gh package
for GitHub API interactions:

Read operations:
- btw_tool_github_issue_get: Read issue description
- btw_tool_github_issue_thread: Read issue with all comments
- btw_tool_github_pull_request_get: Read PR description
- btw_tool_github_pull_request_diff: Read PR file changes
- btw_tool_github_issues_list: List issues with filtering
- btw_tool_github_pull_requests_list: List PRs with filtering

Write operations:
- btw_tool_github_issue_create: Create a new issue
- btw_tool_github_pull_request_create: Create a new PR

Key features:
- Auto-detects owner/repo from git remote using gh::gh_tree_remote()
- Conditional registration (only when gh package is installed)
- Comprehensive test suite with snapshots using posit-dev/btw #1
- Optional filtering by state, labels, author, and assignee

Generated with Claude Code
@gadenbuie
gadenbuie requested a review from simonpcouch October 20, 2025 14:13
@gadenbuie gadenbuie changed the title feat: Add tools for interacting with the GH API feat: Add tools for interacting with the GitHub API Oct 20, 2025

@simonpcouch simonpcouch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just gave a go at this by configuring the gh tool with Claude Code:

claude mcp add -s "user" r-btw -- Rscript -e "btw::btw_mcp_server(btw::btw_tools('docs', 'github'))"

For now, I'm seeing issues with calling the tool via MCP:

⏺ r-btw - btw_tool_github (MCP)(code: "gh(\"/repos/posit-dev/mcptools/issues\",
                                state = \"open\")", _intent: "Fetch open issues
                                for posit-dev/mcptools")
  ⎿  Error: MCP error -32603: could not find function "btw_gh_fields"

@gadenbuie

Copy link
Copy Markdown
Collaborator Author

For now, I'm seeing issues with calling the tool via MCP:

Ooh, I bet I need to do some more work to get the limited R env to find btw tools. My guess is that it's working for me when I use load_all() in a way that breaks when the package is loaded normally. Will investigate this afternoon!

@gadenbuie

Copy link
Copy Markdown
Collaborator Author

@simonpcouch can you point me to where mcptools does the tool calling bit? I can't repro without involving mcptools

@gadenbuie

Copy link
Copy Markdown
Collaborator Author

@simonpcouch I pushed a few changes this morning that may or may not be related, but I was able to use this tool through Claude Code with mcptools as you described without getting the error. Can you try the example again?

@simonpcouch

Copy link
Copy Markdown
Collaborator

Installed the new version and am using successfully via MCP! Thanks for putting time in there.

Seems like both Claude 4.5 Sonnet and GPT-5 are having no trouble using the tool successfully. Super stoked about this feature. :)

@gadenbuie
gadenbuie merged commit a5c4dcc into main Oct 21, 2025
11 checks passed
@gadenbuie
gadenbuie deleted the feat/tools-gh branch October 21, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New feature: GitHub API tool for repository and pull request information

2 participants